package com.jacky.javase;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbcp2.BasicDataSource;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectionTests {
    @Test
    public void testC3P0() throws Exception {
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setDriverClass("com.mysql.cj.jdbc.Driver");
        cpds.setJdbcUrl("jdbc:mysql://localhost:3306/jt");
        cpds.setUser("root");
        cpds.setPassword("root");
        Connection conn = cpds.getConnection();
        System.out.println(conn);
    }

    @Test
    public void testDBCP() throws SQLException {
        BasicDataSource bds = new BasicDataSource();
        bds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        bds.setUrl("jdbc:mysql://localhost:3306/jt");
        bds.setUsername("root");
        bds.setPassword("root");
        Connection conn = bds.getConnection();
        System.out.println(conn);
    }

    @Test
    public void testDruid() throws SQLException {
        DruidDataSource dds = new DruidDataSource();
        dds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dds.setUrl("jdbc:mysql://localhost:3306/jt");
        dds.setUsername("root");
        dds.setPassword("root");
        DruidPooledConnection conn = dds.getConnection();
        System.out.println(conn);
    }


}
